<script setup lang="tsx">
// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 模块导入 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

import { computed, reactive, watch } from 'vue';
import dayjs from 'dayjs';
import { $t } from '@/locales';
import { useNaiveForm } from '@/hooks/common/form';
import { fetchAddRecycle, fetchGetMyUniqueProvinceCityCounty, fetchUpdateRecycle } from '@/service/api';
import { useAuth } from '@/hooks/business/auth';

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 组件名称 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

defineOptions({
  name: 'DimoRecycleOperateModal'
});

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 组合式函数 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

const { validate, restoreValidation } = useNaiveForm();

const { currentOrgPosition, userInfo } = useAuth();

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 父子传参 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

interface Props {
  /** the type of operation */
  operateType: OperateType;
  /** the edit row data */
  rowData?: Api.Dimo.Recycle | null;
}

const props = defineProps<Props>();

interface Emits {
  (e: 'submitted'): void;
}

const emit = defineEmits<Emits>();

const visible = defineModel<boolean>('visible', {
  default: false
});

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架模型 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

export type OperateType = NaiveUI.TableOperateType | 'view';

const isAdd = computed(() => props.operateType === 'add');

const isEdit = computed(() => props.operateType === 'edit');

const isView = computed(() => props.operateType === 'view');

const addKey = computed(() => `DMRECYCLE${userInfo()?.userName}ADD`);

const editKey = computed(() => `DMRECYCLE${userInfo()?.userName}EDIT${props.rowData?.id}`);

const title = computed(() => {
  const titles: Record<OperateType, string> = {
    add: $t('common.add'),
    edit: $t('common.edit'),
    view: '查看'
  };
  return `【${titles[props.operateType]}】农用薄膜使用回收水平调查表`;
});

type Model = Api.Dimo.Recycle;

const model: Model = reactive(createDefaultModel());

function createDefaultModel(): Model {
  return {
    id: '',
    createUser: '',
    createTime: '',
    updateUser: '',
    updateTime: '',
    tenantId: 0,
    orgId: '',
    positionId: '',
    reportUnit: '',
    reportDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    reportPerson: '',
    reportPersonContactInfo: '',
    investPerson: '',
    investPersonContactInfo: '',
    countyAuthStatus: false,
    countyAuthDate: '',
    countyAuthUserId: 0,
    cityAuthStatus: false,
    cityAuthDate: '',
    cityAuthUserId: 0,
    provinceAuthStatus: false,
    provinceAuthDate: '',
    provinceAuthUserId: 0,
    comment: '',
    cultivatedArea: 0,
    sownArea: 0,
    permanentFarmingHousehold: 0,
    pmUser: 0,
    dmUser: 0,
    pmDmUser: 0,
    pmMainCrop: '',
    pmApplyCoverAreaCurrYear: 0,
    pmApplyCoverAreaRemain: 0,
    pmApplyUseCurrYear: 0,
    pmApplyUseRemain: 0,
    pmRecycleUseRemain: 0,
    pmRecycleReplaceCurrYear: 0,
    pmDealUseNextYear: 0,
    pmRuralWasteSite: 0,
    pmRecycleSite: 0,
    pmRecycleCompany: 0,
    pmOther: 0,
    dmMainCrop: '',
    dmApplyAreaCoverAll: 0,
    dmApplyAreaStandard: 0,
    dmApplyAreaThick: 0,
    dmApplyAreaDegrade: 0,
    dmApplyUseTotal: 0,
    dmApplyUseStandard: 0,
    dmApplyUseThick: 0,
    dmApplyUseDegrade: 0,
    dmRecycleManual: 0,
    dmRecycleMachine: 0,
    dmRecycleComplex: 0,
    dmRecycleOther: 0,
    dmRecycleNone: 0,
    dmRecycleCostManual: 0,
    dmRecycleCostMachine: 0,
    dmRecycleCostComplex: 0,
    dmRecycleCostOther: 0,
    dmRecyleResidual: 0,
    dmDealReuseTotal: 0,
    dmDealResuseCompany: 0,
    dmDealHarmlessTotal: 0,
    dmDealHarmlessOther: 0,
    dmDealOther: 0,
    hasNnRecycleSite: false,
    siteRecyclePrice: 0,
    hasNnRecycleCompany: false,
    companyRecyclePrice: 0,
    workPilotFinishAreaTotal: 0,
    workPilotFinishFundTotal: 0,
    workPilotFinishThickTotal: 0,
    workPilotFinishDegradeTotal: 0,
    workFundThick: 0,
    workFundDegrade: 0,
    workFundSubsidy: 0,
    workFundBuilding: 0,
    workTrainTime: 0,
    workTrainReport: 0,
    workTrainMeeting: 0,
    workTrainPerson: 0,
    provinceCityCountyInfo: {
      provinceId: '',
      provinceName: '',
      cityId: '',
      cityName: '',
      countyId: '',
      countyName: ''
    },
    recyclePilots: [createRecyclePilot()]
  };
}

function createRecyclePilot() {
  return {
    id: '',
    createUser: '',
    createTime: '',
    updateUser: '',
    updateTime: '',
    tenantId: '',
    recycleId: '',
    areaTotal: 0,
    fundTotal: 0,
    thickDmAreaTotal: 0,
    degradeDmAreaTotal: 0,
    year: Number.parseInt(dayjs().format('YYYY'), 10)
  };
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 业务模型 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

// const orgType = ref<string>(currentOrgPosition()?.orgType || '');

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架方法 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

function handleInitModel() {
  Object.assign(model, createDefaultModel());

  let localData = null;
  if (props.operateType === 'add') {
    localData = localStorage.getItem(addKey.value);
  } else if (props.operateType === 'edit') {
    localData = localStorage.getItem(editKey.value);
  }

  if (localData) {
    window.$dialog?.info({
      title: $t('common.tip'),
      content: '检测到上次您有未保存的数据，是否继续使用该数据进行操作?',
      positiveText: $t('common.confirm'),
      negativeText: $t('common.cancel'),
      onPositiveClick: () => {
        Object.assign(model, JSON.parse(localData));
      },
      onNegativeClick: () => {
        if (isAdd.value) {
          localStorage.removeItem(addKey.value);
        } else if (isEdit.value) {
          localStorage.removeItem(editKey.value);
        }
        handleAEV();
      }
    });
  } else {
    handleAEV();
  }
}

function handleAEV() {
  if (props.operateType === 'add') {
    model.reportPerson = userInfo()?.realName || '';
    fetchGetMyUniqueProvinceCityCounty().then(({ error, data }) => {
      if (!error && data) {
        model.provinceCityCountyInfo = data;
        model.orgId = data.countyId ?? data.cityId ?? data.provinceId;
      }
    });
  } else if (['edit', 'view'].includes(props.operateType) && props.rowData) {
    const d: Model = JSON.parse(JSON.stringify(props.rowData));
    d.reportDate = dayjs(d.reportDate).format('YYYY-MM-DD HH:mm:ss');
    Object.assign(model, d);
  }
}

function closeModal() {
  visible.value = false;
}

async function handleSubmit() {
  await validate();
  const func = isAdd.value ? fetchAddRecycle : fetchUpdateRecycle;
  if (isAdd.value) {
    model.orgId = currentOrgPosition()?.orgId || '';
    model.positionId = currentOrgPosition()?.positionId || '';
  }
  const { error, data } = await func(model);
  if (!error && data) {
    window.$message?.success(isAdd.value ? $t('common.addSuccess') : $t('common.updateSuccess'));
    if (isAdd.value) {
      localStorage.removeItem(addKey.value);
    } else if (isEdit.value) {
      localStorage.removeItem(editKey.value);
    }
    closeModal();
    emit('submitted');
  }
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 业务方法 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

function plusPilot(index: number) {
  if (model.recyclePilots.length === index + 1) {
    model.recyclePilots.push(createRecyclePilot());
  } else {
    model.recyclePilots.splice(index + 1, 0, createRecyclePilot());
  }
}

function reducePilot(index: number) {
  model.recyclePilots.splice(index, 1);
}

function tempSave() {
  if (isAdd.value) {
    localStorage.removeItem(addKey.value);
    const plainObject = JSON.parse(JSON.stringify(model));
    localStorage.setItem(addKey.value, JSON.stringify(plainObject));
  } else if (isEdit.value) {
    const plainObject = JSON.parse(JSON.stringify(model));
    localStorage.setItem(editKey.value, JSON.stringify(plainObject));
  }
  window.$message?.success('临时保存成功');
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架生命周期 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

watch(visible, () => {
  if (visible.value) {
    handleInitModel();
    restoreValidation();
  }
});
</script>

<template>
  <NModal v-model:show="visible" :title="title" preset="card" class="w-1280px" :close-on-esc="false" :mask-closable="false">
    <div class="info">
      <div class="title-info">
        <NSpace v-if="!isView">
          <div class="w-433px">
            <NInput v-model:value="model.reportUnit" type="text" :disabled="isView">
              <template #prefix>填报单位：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.provinceCityCountyInfo.cityName" type="text" disabled>
              <template #prefix>市：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.provinceCityCountyInfo.countyName" type="text" disabled>
              <template #prefix>县：</template>
            </NInput>
          </div>
          <NDatePicker v-model:formatted-value="model.reportDate" type="date" value-format="yyyy-MM-dd HH:mm:ss" :disabled="isView" />
        </NSpace>
        <NSpace v-else>
          <span class="mr-60px">
            <b>填报单位：</b>
            {{ model.reportUnit }}
          </span>
          <span class="mr-60px">
            <b>市：</b>
            {{ model.provinceCityCountyInfo.cityName }}
          </span>
          <span class="mr-60px">
            <b>县：</b>
            {{ model.provinceCityCountyInfo.countyName }}
          </span>
          <span>
            <b>填报日期：</b>
            {{ dayjs(model.reportDate).format('YYYY-MM-DD') }}
          </span>
        </NSpace>
      </div>
      <div class="table-info">
        <table>
          <thead>
            <tr>
              <th colspan="4">指标名称</th>
              <th class="w-80px text-center">单位</th>
              <th class="w-200px">指标值</th>
            </tr>
          </thead>
          <tbody>
            <!-- 基本情况 -->
            <tr>
              <td rowspan="6">基本情况</td>
              <td colspan="3">耕地面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.cultivatedArea" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.cultivatedArea }}</td>
            </tr>
            <tr>
              <td colspan="3">农作物播种面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.sownArea" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.sownArea }}</td>
            </tr>
            <tr>
              <td colspan="3">常驻农户</td>
              <td class="text-center">户</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.permanentFarmingHousehold" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.permanentFarmingHousehold }}</td>
            </tr>
            <tr>
              <td rowspan="3">用膜农户</td>
              <td colspan="2">棚膜用户</td>
              <td class="text-center">户</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmUser" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.pmUser }}</td>
            </tr>
            <tr>
              <td colspan="2">地膜用户</td>
              <td class="text-center">户</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmUser" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.dmUser }}</td>
            </tr>
            <tr>
              <td colspan="2">棚膜+地膜用户</td>
              <td class="text-center">户</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmDmUser" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.pmDmUser }}</td>
            </tr>
            <!-- 棚膜使用回收情况 -->
            <tr>
              <td rowspan="12">棚膜使用回收情况</td>
              <td rowspan="5">应用情况</td>
              <td colspan="2">域内主要棚膜作物</td>
              <td class="text-center">-</td>
              <td v-if="!isView"><NInput v-model:value="model.pmMainCrop" type="text" size="small" /></td>
              <td v-else class="text-left">{{ model.pmMainCrop }}</td>
            </tr>
            <tr>
              <td rowspan="2">覆盖面积（占地面积）</td>
              <td>当年新投入使用的棚膜覆盖面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmApplyCoverAreaCurrYear" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmApplyCoverAreaCurrYear }}</td>
            </tr>
            <tr>
              <td>之前投入使用且目前仍在继续使用的棚膜覆盖面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmApplyCoverAreaRemain" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmApplyCoverAreaRemain }}</td>
            </tr>
            <tr>
              <td rowspan="2">使用量</td>
              <td>当年新投入使用的棚膜量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmApplyUseCurrYear" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmApplyUseCurrYear }}</td>
            </tr>
            <tr>
              <td>之前投入使用且目前仍在继续使用的棚膜量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmApplyUseRemain" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmApplyUseRemain }}</td>
            </tr>
            <tr>
              <td rowspan="2">回收情况</td>
              <td rowspan="2">回收量</td>
              <td>之前投入使用且目前仍在继续使用的棚膜量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmRecycleUseRemain" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmRecycleUseRemain }}</td>
            </tr>
            <tr>
              <td>当年被替换下来的旧膜量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmRecycleReplaceCurrYear" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmRecycleReplaceCurrYear }}</td>
            </tr>
            <tr>
              <td rowspan="5">处置情况</td>
              <td colspan="2">次年继续棚膜覆膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmDealUseNextYear" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmDealUseNextYear }}</td>
            </tr>
            <tr>
              <td colspan="2">清运至农村生活垃圾回收处置点</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmRuralWasteSite" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmRuralWasteSite }}</td>
            </tr>
            <tr>
              <td colspan="2">回收至废旧农膜回收处置站（点）</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmRecycleSite" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmRecycleSite }}</td>
            </tr>
            <tr>
              <td colspan="2">回收至废旧农膜回收利用企业</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmRecycleCompany" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmRecycleCompany }}</td>
            </tr>
            <tr>
              <td colspan="2">其他</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.pmOther" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.pmOther }}</td>
            </tr>
            <!-- 地膜使用回收情况 -->
            <tr>
              <td rowspan="24">地膜使用回收情况</td>
              <td rowspan="9">应用情况</td>
              <td colspan="2">域内主要地膜覆膜作物</td>
              <td class="text-center">-</td>
              <td v-if="!isView"><NInput v-model:value="model.dmMainCrop" type="text" size="small" /></td>
              <td v-else class="text-left">{{ model.dmMainCrop }}</td>
            </tr>
            <tr>
              <td rowspan="4">覆膜面积</td>
              <td>覆膜面积（总）</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyAreaCoverAll" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyAreaCoverAll }}</td>
            </tr>
            <tr>
              <td>其中，标准地膜</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyAreaStandard" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyAreaStandard }}</td>
            </tr>
            <tr>
              <td>其中，加厚高强度地膜</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyAreaThick" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyAreaThick }}</td>
            </tr>
            <tr>
              <td>其中，全生物降解地膜</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyAreaDegrade" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyAreaDegrade }}</td>
            </tr>
            <tr>
              <td rowspan="4">使用量</td>
              <td>使用量（总）</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyUseTotal" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyUseTotal }}</td>
            </tr>
            <tr>
              <td>其中，标准地膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyUseStandard" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyUseStandard }}</td>
            </tr>
            <tr>
              <td>其中，加厚高强度地膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyUseThick" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyUseThick }}</td>
            </tr>
            <tr>
              <td>其中，全生物降解地膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmApplyUseDegrade" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmApplyUseDegrade }}</td>
            </tr>
            <tr>
              <td rowspan="10">回收情况</td>
              <td rowspan="5">回收作业面积</td>
              <td>人工捡拾</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleManual" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleManual }}</td>
            </tr>
            <tr>
              <td>机械回收</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleMachine" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleMachine }}</td>
            </tr>
            <tr>
              <td>复合回收（人工+机械）</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleComplex" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleComplex }}</td>
            </tr>
            <tr>
              <td>其他方式回收</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleOther" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleOther }}</td>
            </tr>
            <tr>
              <td>不回收</td>
              <td class="text-center">亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleNone" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleNone }}</td>
            </tr>
            <tr>
              <td rowspan="4">回收成本</td>
              <td>人工捡拾</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleCostManual" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleCostManual }}</td>
            </tr>
            <tr>
              <td>机械回收</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleCostMachine" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleCostMachine }}</td>
            </tr>
            <tr>
              <td>复合回收（人工+机械）</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleCostComplex" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleCostComplex }}</td>
            </tr>
            <tr>
              <td>其他方式回收</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecycleCostOther" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecycleCostOther }}</td>
            </tr>
            <tr>
              <td colspan="2">残膜回收（离田）量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmRecyleResidual" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmRecyleResidual }}</td>
            </tr>
            <tr>
              <td rowspan="5">处置情况</td>
              <td rowspan="2">资源化再利用量</td>
              <td>资源化利用量（总）</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmDealReuseTotal" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmDealReuseTotal }}</td>
            </tr>
            <tr>
              <td>其中，清运至废旧农膜回收利用企业资源再利用</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmDealResuseCompany" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmDealResuseCompany }}</td>
            </tr>
            <tr>
              <td rowspan="2">无害化处理量</td>
              <td>无害化处理量（总）</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmDealHarmlessTotal" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmDealHarmlessTotal }}</td>
            </tr>
            <tr>
              <td>其中，进入农村生活垃圾处理系统焚烧、卫生填埋、有序堆放等其他无害化处理方式</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmDealHarmlessOther" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmDealHarmlessOther }}</td>
            </tr>
            <tr>
              <td colspan="2">其他处置方式</td>
              <td class="text-center">千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.dmDealOther" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.dmDealOther }}</td>
            </tr>
            <!-- 废旧农膜回收站点 -->
            <tr>
              <td rowspan="2">废旧农膜回收站点</td>
              <td colspan="3">废旧农膜回收站点</td>
              <td class="text-center">有/无</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.hasNnRecycleSite">
                  <NRadio :value="true" label="有" />
                  <NRadio :value="false" label="无" />
                </NRadioGroup>
              </td>
              <td v-else class="text-center">{{ model.hasNnRecycleSite ? '有' : '无' }}</td>
            </tr>
            <tr>
              <td colspan="3">回收价格</td>
              <td class="text-center">元/千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.siteRecyclePrice" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.siteRecyclePrice }}</td>
            </tr>
            <!-- 废旧农膜回收再企业 -->
            <tr>
              <td rowspan="2">废旧农膜回收再企业</td>
              <td colspan="3">废旧农膜回收再利用企业</td>
              <td class="text-center">有/无</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.hasNnRecycleCompany">
                  <NRadio :value="true" label="有" />
                  <NRadio :value="false" label="无" />
                </NRadioGroup>
              </td>
              <td v-else class="text-center">{{ model.hasNnRecycleCompany ? '有' : '无' }}</td>
            </tr>
            <tr>
              <td colspan="3">回收价格</td>
              <td class="text-center">元/千克</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.companyRecyclePrice" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.companyRecyclePrice }}</td>
            </tr>
            <!-- 工作开展情况 -->
            <template v-for="(row, index) in model.recyclePilots" :key="index">
              <tr>
                <td v-if="index === 0" :rowspan="model.recyclePilots.length * 5 + 12">工作开展情况</td>
                <td v-if="index === 0" :rowspan="model.recyclePilots.length * 5 + 4">试点工作</td>
                <td rowspan="5">
                  <div>{{ row.year }} 年试点任务</div>
                  <div v-if="!isView">
                    <NSpace>
                      <NButton ghost circle type="primary" size="tiny" @click="plusPilot(index)">
                        <template #icon>
                          <icon-carbon:add />
                        </template>
                      </NButton>
                      <NButton v-if="model.recyclePilots.length > 1" ghost circle type="primary" size="tiny" @click="reducePilot(index)">
                        <template #icon>
                          <icon-carbon:close />
                        </template>
                      </NButton>
                    </NSpace>
                  </div>
                </td>
                <td>年份</td>
                <td class="text-center">-</td>
                <td v-if="!isView"><NInputNumber v-model:value="row.year" clearable :precision="0" size="small" /></td>
                <td v-else class="text-center">{{ row.year }}</td>
              </tr>
              <tr>
                <td>试点任务面积（总）</td>
                <td class="text-center">万亩</td>
                <td v-if="!isView"><NInputNumber v-model:value="row.areaTotal" clearable :precision="2" size="small" /></td>
                <td v-else class="text-right">{{ row.areaTotal }}</td>
              </tr>
              <tr>
                <td>试点任务资金</td>
                <td class="text-center">万元</td>
                <td v-if="!isView"><NInputNumber v-model:value="row.fundTotal" clearable :precision="2" size="small" /></td>
                <td v-else class="text-right">{{ row.fundTotal }}</td>
              </tr>
              <tr>
                <td>加厚高强度地膜任务面积</td>
                <td class="text-center">万亩</td>
                <td v-if="!isView"><NInputNumber v-model:value="row.thickDmAreaTotal" clearable :precision="2" size="small" /></td>
                <td v-else class="text-right">{{ row.thickDmAreaTotal }}</td>
              </tr>
              <tr>
                <td>全生物降解地膜任务面积</td>
                <td class="text-center">万亩</td>
                <td v-if="!isView"><NInputNumber v-model:value="row.degradeDmAreaTotal" clearable :precision="2" size="small" /></td>
                <td v-else class="text-right">{{ row.degradeDmAreaTotal }}</td>
              </tr>
            </template>
            <tr>
              <td rowspan="4">完成试点任务</td>
              <td>完成试点任务面积（总）</td>
              <td class="text-center">万亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workPilotFinishAreaTotal" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workPilotFinishAreaTotal }}</td>
            </tr>
            <tr>
              <td>完成验收补贴到位资金</td>
              <td class="text-center">万元</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workPilotFinishFundTotal" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workPilotFinishFundTotal }}</td>
            </tr>
            <tr>
              <td>加厚高强度地膜任务面积</td>
              <td class="text-center">万亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workPilotFinishThickTotal" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workPilotFinishThickTotal }}</td>
            </tr>
            <tr>
              <td>全生物降解地膜任务面积</td>
              <td class="text-center">万亩</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workPilotFinishDegradeTotal" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workPilotFinishDegradeTotal }}</td>
            </tr>
            <tr>
              <td rowspan="4">资金投入</td>
              <td colspan="2">加厚高强度地膜推广</td>
              <td class="text-center">万元</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workFundThick" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workFundThick }}</td>
            </tr>
            <tr>
              <td colspan="2">全生物降解地膜推广</td>
              <td class="text-center">万元</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workFundDegrade" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workFundDegrade }}</td>
            </tr>
            <tr>
              <td colspan="2">回收作业补贴</td>
              <td class="text-center">万元</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workFundSubsidy" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workFundSubsidy }}</td>
            </tr>
            <tr>
              <td colspan="2">回收体系建设投入</td>
              <td class="text-center">万元</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workFundBuilding" clearable :precision="2" size="small" /></td>
              <td v-else class="text-right">{{ model.workFundBuilding }}</td>
            </tr>
            <tr>
              <td rowspan="4">宣传培训</td>
              <td colspan="2">开展宣传活动</td>
              <td class="text-center">次</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workTrainTime" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.workTrainTime }}</td>
            </tr>
            <tr>
              <td colspan="2">信息报道</td>
              <td class="text-center">次</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workTrainReport" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.workTrainReport }}</td>
            </tr>
            <tr>
              <td colspan="2">举办培训或相关会议</td>
              <td class="text-center">次</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workTrainMeeting" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.workTrainMeeting }}</td>
            </tr>
            <tr>
              <td colspan="2">培训人员</td>
              <td class="text-center">人次</td>
              <td v-if="!isView"><NInputNumber v-model:value="model.workTrainPerson" clearable :precision="0" size="small" /></td>
              <td v-else class="text-right">{{ model.workTrainPerson }}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="foot-info">
        <NGrid v-if="!isView" x-gap="12" :cols="4">
          <NGi>
            <NInput v-model:value="model.reportPerson" :disabled="isView">
              <template #prefix>填报人：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.reportPersonContactInfo" :disabled="isView">
              <template #prefix>联系方式：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.investPerson" :disabled="isView">
              <template #prefix>调查员：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.investPersonContactInfo" :disabled="isView">
              <template #prefix>联系方式：</template>
            </NInput>
          </NGi>
        </NGrid>
        <NSpace v-else>
          <span class="mr-60px">
            <b>填报人：</b>
            {{ model.reportPerson }}
          </span>
          <span class="mr-60px">
            <b>联系方式：</b>
            {{ model.reportPersonContactInfo }}
          </span>
          <span class="mr-60px">
            <b>调查员：</b>
            {{ model.investPerson }}
          </span>
          <span>
            <b>联系方式：</b>
            {{ model.investPersonContactInfo }}
          </span>
        </NSpace>
        <div class="h-12px"></div>
        <NInput v-if="!isView" v-model:value="model.comment" type="textarea" placeholder="备注" :disabled="isView" />
        <span v-else>
          <b>备注：</b>
          {{ model.comment }}
        </span>
      </div>
    </div>
    <template #footer>
      <NSpace v-if="!isView" justify="end">
        <NButton type="warning" @click="tempSave">临时保存</NButton>
        <NButton type="error" @click="closeModal">
          {{ $t('common.cancel') }}
        </NButton>
        <NButton type="primary" @click="handleSubmit">
          {{ $t('common.save') }}
        </NButton>
      </NSpace>
    </template>
  </NModal>
</template>

<style lang="scss" scoped>
.info {
  .title-info {
    margin-bottom: 12px;
  }

  .table-info {
    table {
      width: 100%;
      border-top: 1px solid #e5e7eb;
      border-left: 1px solid #e5e7eb;
      margin-bottom: 12px;

      th,
      td {
        border-right: 1px solid #e5e7eb;
        border-bottom: 1px solid #e5e7eb;
        padding: 5px;
      }
    }
  }
}
</style>
